var express = require("express");
var router = express.Router();
var query = require("../conn/conn");

/* GET home page. */
router.get("/", function (req, res, next) {
  res.render("index", { title: "Express" });
});
router.get("/recommend",async function (req, res, next) {
    // let res=await query(`INSERT INTO recommend( masterImg, picure, title, label, username, headImg, browse, likes) VALUES ('${req.query.zhutu}','${req.query.lunbo}','${req.query.title}','${req.query.biaoqian}','${req.query.user}','${req.query.touxiang}','${req.query.liulan}','${req.query.dianzan}'`)
    let ress=await query(`INSERT INTO recommend( masterImg, picure, title, label, username, headImg, browse, likes) VALUES ('${req.query.zhutu}','${req.query.lunbo}','${req.query.title}','${req.query.biaoqian}','${req.query.user}','${req.query.touxiang}','${req.query.liulan}','${req.query.dianzan}')`);
    res.send({status:0,msg:'插入成功'});
});
router.get('/exhibition',async (req,res,next)=>{
    function random(min,max){
        return Math.floor(Math.random()*(max-min))+ min;
    }
    
    let ress=await query(`INSERT INTO exhibition( masterImg, title, time, addr, price, want,type,open) VALUES ('${req.query.zhutu}','${req.query.title}','${req.query.time}','${req.query.addr}','${req.query.jine}','${req.query.xiangqu}','${random(1,7)}','${random(0,2)}')`);
    res.send({status:0,msg:"插入成功"})
});

router.get('/showtime',async (req,res,next)=>{
    function random(min,max){
        return Math.floor(Math.random()*(max-min))+ min;
    }
    let ress=await query(`INSERT INTO showtime( masterImg, title, time, addr, price, want,type,open,tacketinfo,address) VALUES ('${req.query.zhutu}','${req.query.title}','${req.query.time}','${req.query.addr}','${req.query.jine}','${req.query.xiangqu}','${random(1,7)}','${random(0,2)}','${req.query.tacketinfo}','${req.query.address}')`);
    res.send({status:0,msg:"插入成功"})
});

router.get('/music',async (req,res,next)=>{
    function random(min,max){
        return Math.floor(Math.random()*(max-min))+ min;
    }
    let ress=await query(`INSERT INTO music( masterImg, title, time, addr, price, want,type,open,tacketinfo,address) VALUES ('${req.query.zhutu}','${req.query.title}','${req.query.time}','${req.query.addr}','${req.query.jine}','${req.query.xiangqu}','${random(1,7)}','${random(0,2)}','${req.query.tacketinfo}','${req.query.address}')`);
    res.send({status:0,msg:"插入成功"})
});

router.get('/ifc',async (req,res,next)=>{
    function random(min,max){
        return Math.floor(Math.random()*(max-min))+ min;
    }
    let ress=await query(`INSERT INTO ifc( masterImg, title, time, addr, price, want,type,open,tacketinfo,address) VALUES ('${req.query.zhutu}','${req.query.title}','${req.query.time}','${req.query.addr}','${req.query.jine}','${req.query.xiangqu}','${random(1,7)}','${random(0,2)}','${req.query.tacketinfo}','${req.query.address}')`);
    res.send({status:0,msg:"插入成功"})
});

router.get('/dance',async (req,res,next)=>{
    function random(min,max){
        return Math.floor(Math.random()*(max-min))+ min;
    }
    let ress=await query(`INSERT INTO dance( masterImg, title, time, addr, price, want,type,open,tacketinfo,address) VALUES ('${req.query.zhutu}','${req.query.title}','${req.query.time}','${req.query.addr}','${req.query.jine}','${req.query.xiangqu}','${random(1,7)}','${random(0,2)}','${req.query.tacketinfo}','${req.query.address}')`);
    res.send({status:0,msg:"插入成功"})
});


router.get('/market',async(req,res,next)=>{
    let ress=await query(`INSERT INTO market(title, masterImg, label, price, likes) VALUES ('${req.query.title}','${req.query.masterImg}','${req.query.label}','0','0')`);
    res.send({status:0,msg:"插入成功"})
})
module.exports = router;